package com.culture.config.service.impl;

import java.util.Collections;
import java.util.List;

import javax.annotation.Resource;

import com.culture.config.common.util.BeanUtil;
import com.culture.config.dao.entity.Role;
import com.culture.config.dao.mapper.RoleMapper;
import com.culture.config.service.RoleService;
import com.culture.config.model.po.*;
import com.culture.config.model.vo.*;
import com.culture.config.wrapper.RoleWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.page.PageMethod;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class RoleServiceImpl implements RoleService{
    @Resource
    private RoleMapper roleMapper;
    
    @Override
    public Page<RoleVO> page(RolePageParam param) {
        log.info("page:{}",param);
        PageMethod.startPage(param.getPageNum(),param.getPageSize());
		Page<Role> roleList = this.roleMapper.page(RoleWrapper.wrapRoleQuery(param));      
		return BeanUtil.copyPageProperties(roleList, RoleVO.class);
    }

    @Override
    public void add(RoleAddPO roleAddPO) {
        log.info("add:{}",roleAddPO);
        this.roleMapper.add(RoleWrapper.wrapRoleAdd(roleAddPO));
    }

    @Override
    public void update(RoleUpdatePO roleUpdatePO) {
        log.info("update:{}",roleUpdatePO);
        this.roleMapper.update(RoleWrapper.wrapRoleUpdate(roleUpdatePO));
    }

    @Override
    public List<RoleVO> list(RoleSearchPO param) {       
        List<Role> roleList = this.roleMapper.list(RoleWrapper.wrapRoleSearch(param));
        if(CollectionUtils.isEmpty(roleList)){
            return Collections.emptyList();
        }
        return BeanUtil.copyListProperties(roleList, RoleVO.class);
    }  

}
